package com.action.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.server.ServerWebExchange;

/**
 * @ClassName GulimallCrosWebFilter
 * @Deacription TODO
 * @Author sl
 * @Date 2021/6/11/011 15:30
 * @Version 1.0
 **/
@Configuration
public class GulimallCrosConfiguration{

    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration ccf = new CorsConfiguration();
        //配置跨域
        ccf.addAllowedOrigin("*");
        ccf.addAllowedHeader("*");
        ccf.addAllowedMethod("*");
        ccf.setAllowCredentials(true);
        source.registerCorsConfiguration("/**",ccf);
        return new CorsWebFilter(source);
    }
}
